﻿///<copyright>
/// Copyright © 2009 Stephen Styrchak. All Rights Reserved.
///</copyright>
using System;
using System.ComponentModel;
using System.Diagnostics;
using Ferpect.ComponentModel.Sprites;

namespace Ferpect.ComponentModel.Design
{
    public class ImageSpriteDesigner : SpriteDesigner
    {
        public override bool SpriteCanMove
        {
            get
            {
                ImageSprite imageSprite = this.Component as ImageSprite;
                if (imageSprite != null)
                {
                    return !imageSprite.FullScreen;
                }
                Debug.Fail("The ImageSpriteDesigner is being used with a sprite that it doesn't recognize.");
                return true;
            }
        }

        /// <summary>
        /// The property is wrapped in a method so that we can use a delegate to call it.
        /// </summary>
        private bool GetMovePropertiesReadOnly()
        {
            return !this.SpriteCanMove;
        }

        protected override void PostFilterProperties(System.Collections.IDictionary properties)
        {
            string[] moveProperties = { "Offset", "RelativeOrigin", "Anchor" };

            foreach (string propertyName in moveProperties)
            {
                PropertyDescriptor property = properties[propertyName] as PropertyDescriptor;
                if (property != null)
                {
                    PropertyDescriptorWrapper wrapper = new DynamicReadOnlyPropertyDescriptor(property, this.GetMovePropertiesReadOnly);
                    properties[propertyName] = wrapper;
                }
            }
            base.PostFilterProperties(properties);
        }
    }
}
